package com.dm.script;

import com.alibaba.fastjson.JSONObject;
import com.dm.script.entity.Demo;
import com.dm.script.jdbc.mapper.DemoMapper;
import com.dm.script.mongo.MongoService;
import com.dm.script.redis.RedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@SpringBootApplication
@ComponentScan("com.dm.script")
@RestController
public class ScriptApplication {
    @Autowired
    private RedisService redisService;
    @Autowired
    private MongoService mongoService;
    @Autowired
    private DemoMapper demoMapper;

    public static void main(String[] args) {
        SpringApplication.run(ScriptApplication.class, args);
    }

    @RequestMapping("/")
    public String index() {
        //测试 Redis
        redisService.setKey("test123", "qwe123");
        System.out.println(redisService.getKey("test123"));
        //测试mongo
        JSONObject data = new JSONObject();
        data.fluentPut("userId", "3333");
        data.fluentPut("data", new ArrayList<>().add("qwe123123"));
        mongoService.testInsert(data);
        Query userId = new Query(Criteria.where("userId").is("3333"));
        List<JSONObject> jsonObjects = mongoService.testFind(userId);
        for (JSONObject jsonObject : jsonObjects) {
            System.out.println(jsonObject);
        }
        List<Demo> demos = demoMapper.selectList();
        return "success full  mysql dara--->" + JSONObject.toJSONString(demos);
    }
}
